#pragma once

#include <iostream>

#include "Protocol.hpp"

class Calculator
{
public:
    Calculator()
    {
    }
    Response Calculate(const Request &rq)
    {
        Response resp;
        switch (rq.Op())
        {
        case '+':
            resp.SetResult(rq.X() + rq.Y());
            break;
        case '-':
            resp.SetResult(rq.X() - rq.Y());
            break;
        case '*':
            resp.SetResult(rq.X() * rq.Y());
            break;
        case '/':
        {
            if (rq.Y() == 0)
            {
                resp.SetCode(1); // 1 除 0
            }
            else
            {
                resp.SetResult(rq.X() / rq.Y());
            }
            break;
        }
        case '%':
        {
            if (rq.Y() == 0)
            {
                resp.SetCode(2);  // 2 模 0
            }
            else
            {
                resp.SetResult(rq.X() % rq.Y());
            }
            break;
        }
        default:
            resp.SetCode(3); // 用户发来的计算类型无法识别
            break;
        }
        return resp;
    }
    ~Calculator()
    {
    }
};